package com.joysuch.wwyt.edu.entity;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.joysuch.wwyt.core.support.AutoSetCommonFieldListener;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.hibernate.annotations.SQLDelete;
import org.hibernate.annotations.SQLDeleteAll;
import org.hibernate.annotations.Where;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import javax.persistence.*;

import static javax.persistence.GenerationType.IDENTITY;

/**
 * @Author ZhangDong
 * @Date 2020/6/24 17:16
 */
@EntityListeners({AuditingEntityListener.class, AutoSetCommonFieldListener.class})
@Entity
@Table(name = "wwyt_edu_course_statistics")
@SQLDelete(sql = "update wwyt_course_statistics set DELETE_FLAG = '1' where id= ?")
@SQLDeleteAll(sql = "update wwyt_course_statistics set DELETE_FLAG = '1' where id= ?")
@Where(clause = "DELETE_FLAG = '0'")
@Data
public class EduCourseStatistics {

    @Id
    @GeneratedValue(strategy = IDENTITY)
    @ApiModelProperty("主键ID")
    private Long id;

    @ApiModelProperty("人员id")
    private Long userId;

    @ApiModelProperty("课程学习时长-秒")
    private Long courseLearnTime = 0L;

    @ApiModelProperty("app-学习时长")
    @Transient
    private String appLearnTime;

    @ApiModelProperty("考试次数")
    private Integer examCount = 0;

    @ApiModelProperty("考试通过次数")
    private Integer examPassCount = 0;

    @ApiModelProperty("已学习课件-json")
    private String coursewareLearned;

    @Transient
    private String userName;

    //通用字段
    @ApiModelProperty("创建人")
    @org.springframework.data.annotation.CreatedBy
    @JsonIgnore
    private Long createBy;

    @ApiModelProperty("创建时间")
    @org.springframework.data.annotation.CreatedDate
    private java.time.LocalDateTime createTime;

    @ApiModelProperty("更新人")
    @org.springframework.data.annotation.LastModifiedBy
    @JsonIgnore
    private Long updateBy;

    @ApiModelProperty("更新时间")
    @org.springframework.data.annotation.LastModifiedDate
    @JsonIgnore
    private java.time.LocalDateTime updateTime;

    @ApiModelProperty("租户")
    private Long tenentId;

    @ApiModelProperty("组织机构代码")
    private String orgCode;

    @ApiModelProperty("删除标记")
    @JsonIgnore
    private String deleteFlag;

    public EduCourseStatistics() {
    }

    public EduCourseStatistics(Long courseLearnTime, String userName ,Long userId) {
        this.courseLearnTime = courseLearnTime;
        this.userName = userName;
        this.userId = userId;
    }
}
